home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / xtmui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  7.0 KB  |  274 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      xtmui
  20.    PURPOSE
  21.      
  22.    NOTES
  23.      
  24.    HISTORY
  25.      terjepe - Jul 16, 1996: Created.
  26. ***/
  27.  
  28. #include <intuition/intuition.h>
  29. #include <clib/intuition_protos.h>
  30.  
  31. #include <proto/intuition.h>
  32. #include <proto/graphics.h>
  33. #include <proto/gadtools.h>
  34. #include <assert.h>
  35. #include <stdio.h>
  36.  
  37. #include "libX11.h"
  38.  
  39. #define XLIB_ILLEGAL_ACCESS 1
  40.  
  41. #include <X11/X.h>
  42. #include <X11/Xlib.h>
  43. #include <X11/Xutil.h>
  44. #include <X11/Intrinsic.h>
  45. #include <X11/IntrinsicP.h>
  46. #include <X11/CoreP.h>
  47. #include <X11/Stringdefs.h>
  48.  
  49. #include <X11/Xaw/Command.h>
  50. #include <X11/Xaw/Box.h>
  51.  
  52. #include "amigax_proto.h"
  53. #include "amiga_x.h"
  54.  
  55. #include "xtmui.h"
  56.  
  57. #ifdef XTMUI
  58. #include <libraries/mui.h>
  59. #include <proto/muimaster.h>
  60.  
  61. ObjApp_t *X11App = NULL;
  62.  
  63. ObjApp_t *createMUI_app(char *title);
  64.  
  65. extern Screen  amiga_screen[];
  66. extern ListNode_t *pWidgetList,*pStringList;
  67.  
  68.  
  69. Widget XtAppInitialize(app_context_return, application_class, options,
  70.                num_options, argc_in_out, argv_in_out, fallback_resources, args,
  71.                num_args)
  72.      XtAppContext *app_context_return;
  73.      _Xconst _XtString application_class;
  74.      XrmOptionDescList options;
  75.      Cardinal num_options;
  76.      int *argc_in_out;           /* was type Cardinal * in R4 */
  77.      String *argv_in_out;
  78.      String *fallback_resources;
  79.      ArgList args;
  80.      Cardinal num_args;
  81. {
  82.   ObjApp_t *pObjApp;
  83.   Widget w,root;
  84.  
  85.   XOpenDisplay("");
  86.   X11mui_init();
  87.   pObjApp=createMUI_app("Test");
  88.   w=MakeWidget(NULL,(Object*)pObjApp->Canvas);
  89.   root=MakeWidget(NULL,(Object*)pObjApp->Root);
  90.   w->core.screen=&amiga_screen[0];
  91.   w->core.screen->display=root;
  92.   w->core.widget_class=X11_FORMDIALOG;
  93.   return w;
  94. }
  95.  
  96. Widget XtAppCreateShell(application_name, application_class,
  97.             widget_class, display, args, num_args)
  98.      _Xconst _XtString application_name;
  99.      _Xconst _XtString application_class;
  100.      WidgetClass widget_class;
  101.      Display *display;
  102.      ArgList args;
  103.      Cardinal num_args;
  104. {
  105.   return XmCreateFormDialog (display, application_name,NULL,NULL);
  106. }
  107.  
  108. #if 0
  109. Widget XtCreateManagedWidget(
  110.     _Xconst _XtString      name ,
  111.     WidgetClass      widget_class ,
  112.     Widget          parent ,
  113.     ArgList          args ,
  114.     Cardinal          num_args 
  115. )
  116. {/*   File 'e_edit.o'*/
  117. #if (DEBUGXEMUL_ENTRY) || (DEBUGXEMUL_WARNING)
  118.   printf("WARNING: XtCreateManagedWidget\n");
  119. #endif
  120.   printf("name %s\n",name);
  121.   printf("widget class %s\n",widget_class);
  122.   printf("parent %d\n",parent);
  123.   return(0);
  124. }
  125. #endif
  126.  
  127. ObjApp_t *createMUI_app(char *title){
  128.   struct ObjApp * Object;
  129.  
  130.   if (!(Object = AllocVec( sizeof( struct ObjApp ), MEMF_PUBLIC|MEMF_CLEAR ))) return( NULL );
  131.   Object->App = ApplicationObject,
  132.         MUIA_Application_Author, "TP",
  133.         MUIA_Application_Base, "NONE",
  134.         MUIA_Application_Title, title,
  135.         MUIA_Application_Version, "$VER: NONE XX.XX (XX.XX.XX)",
  136.         MUIA_Application_Copyright, "NOBODY",
  137.         MUIA_Application_Description, "NONE",
  138.         SubWindow, Object->Root = WindowObject,
  139.           WindowContents, Object->Canvas=GroupObject, End,
  140.         End,  
  141.   End;
  142.  
  143.   if (!(Object->App)){
  144.     FreeVec(Object);
  145.     Object = NULL;
  146.   }
  147.   return(Object);
  148. }
  149.  
  150.  
  151. Widget XtInitialize(shell_name, application_class, options,
  152.             num_options, argc, argv)
  153.      String shell_name;    /* unused */
  154.      String application_class;
  155.      XrmOptionDescRec options[];
  156.      Cardinal num_options;
  157.      Cardinal *argc;
  158.      char *argv[];
  159.  
  160. {/*            File 'xlogo.o'*/
  161. #ifdef DEBUGXEMUL
  162.   printf("XtInitialize\n");
  163. #endif
  164.   X11App=createMUI_app(shell_name);
  165.  
  166.   return(X11App->App);
  167. }
  168.  
  169. void XtMainLoop(){/*              File 'xlogo.o'*/
  170.   int running=TRUE;
  171.   ULONG sigs;
  172. #ifdef DEBUGXEMUL
  173.   printf("XtMainLoop\n");
  174. #endif
  175. /*  XtAppMainLoop(amiga_Context);*/
  176.   while (running){
  177.     switch (DoMethod(X11App->App,MUIM_Application_Input,&sigs)){
  178.     case MUIV_Application_ReturnID_Quit: running=FALSE;
  179.       break;
  180.     }
  181.     if (running && sigs) Wait(sigs);
  182.   }
  183.   return(0);
  184. }
  185.  
  186. /*
  187. extern struct IClass *MyClass;
  188. #define MyObject NewObject(MyClass,NULL
  189. */
  190.  
  191. const ULONG sourcecolors[6] ={
  192.   0xb4b4b4b4,0xb4b4b4b4,0xb4b4b4b4,
  193.   0x00000000,0x00000000,0x00000000,
  194. };
  195.  
  196. Widget XtCreateManagedWidget(name, widget_class, parent,
  197.                  args, num_args)
  198.      String name;
  199.      WidgetClass widget_class;
  200.      Widget parent;
  201.      ArgList args;
  202.      Cardinal num_args;
  203. {
  204.   Object *newobj=NULL,*bmobj=NULL;
  205.   if(args && args[0].name==XtNbitmap){
  206.     struct BitMap *bm=(struct BitMap*)args[0].value;
  207.     bmobj=BitmapObject,
  208.       ButtonFrame,
  209.       MUIA_InputMode, MUIV_InputMode_RelVerify,
  210.       MUIA_Bitmap_Bitmap,bm,
  211.       MUIA_Bitmap_Height,bm->Rows,
  212.       MUIA_Bitmap_Width,bm->BytesPerRow*8,
  213.       MUIA_FixWidth,bm->BytesPerRow*8,
  214.       MUIA_FixHeight,bm->Rows,
  215.       MUIA_Bitmap_Transparent,0,
  216.       MUIA_Bitmap_SourceColors,sourcecolors,
  217.       MUIA_Background,MUII_ButtonBack,
  218.     End;
  219.   }
  220.  
  221. /*
  222.   case xmDrawingAreaWidgetClass:
  223.     newobj=MyObject,
  224.         MUIA_FixWidth,100,
  225.     MUIA_FixHeight,100,
  226.       End;
  227.     break;*/
  228.   if(widget_class==commandWidgetClass){
  229.     if(bmobj){
  230.       newobj=bmobj;
  231.       DoMethod(parent,OM_ADDMEMBER,newobj);
  232.     } else
  233.       return XmCreatePushButton(parent,name,args,num_args);
  234.   } else if( widget_class==boxWidgetClass )
  235.     return XmCreateRowColumn(parent,name,args,num_args);
  236.   else { /* custom widget */
  237.     Widget w=(Widget)calloc(widget_class->core_class.widget_size,1);
  238.     Object *g;
  239.  
  240.     if(widget_class->core_class.widget_size<sizeof(struct _WidgetRec)){
  241.       printf("widget class too small!\n");
  242.       return(0);
  243.     }
  244.     if(!w) X11resource_exit(XTMUI1);
  245.     List_AddEntry(pWidgetList,(void*)w);
  246.     memcpy(w,widget_class,sizeof(struct _WidgetRec));
  247.     w->core.parent=parent;
  248.  
  249.     g=GroupObject,
  250.     End;
  251.     DoMethod(X11DrawablesMUI[X11DrawablesMap[(XID)parent->core.self]],OM_ADDMEMBER,g);
  252.     w->core.self=(struct _CorePart *)X11NewMUI(g);
  253.     w->core.widget_class=X11_DRAWINGAREA;
  254.     return w;
  255.   }
  256. }
  257.  
  258. void XtDestroyWidget(w)
  259.      Widget w;
  260. {
  261. }
  262.  
  263.  
  264. void XtRealizeWidget(w)
  265.      Widget w;
  266. {
  267.   if((int)w->core.widget_class!=X11_FORMDIALOG) 
  268.     XtManageChild(w);
  269.   else
  270.     set(X11DrawablesMUI[X11DrawablesMap[(XID)w->core.self]],MUIA_Window_Open,TRUE);
  271. }
  272.  
  273. #endif /* XTMUI */
  274.